// packageI/anytime_service/my/area_manage/area_manage.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    total_page:1,
    keyword: "",
    active: 1,
    list:[],
    can_operate:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.getValidate();
    this.getData();
  },
  getValidate() {
    app._getNetWork({
      url:app.getNetAddresss('plugin.be-within-call.frontend.area-manage.limit'),
      success:resdata=>{
        let {result,data} = resdata.data;
        if(result){
          if(data.can_operate){
            this.setData({
              can_operate:true
            })
          }
        }
      }
    });
  },
  getData(page =1 ){
    let json = {
      state:this.data.active,
      page
    }
    if (this.data.keyword) {
      json.name = this.data.keyword;
    }
    app._getNetWork({
      url:app.getNetAddresss('plugin.be-within-call.frontend.area-manage.shi-fu-list'),
      data:json,
      success:resdata=>{
        let {result,data} = resdata.data;
        if(result){
          this.data.page = data.current_page;
          this.data.total_page = data.last_page;
            if(page == 1){
              this.setData({list:data.data})
            }else{
              let list = this.data.list.concat(data.data);
              this.setData({list})
            }
        }
      }
    })
  },

  onClick(e){
    this.setData({active:e.detail.name});
    this.getData()
  },
  link(e){
    let item = e.currentTarget.dataset.item;
    let apply_type =3;
    wx.navigateTo({
      url: '/packageJ/anytime_service/my/role_apply_for/master_worker/master_worker?uid='+ item.has_one_member.uid +'&apply_type='+apply_type,
    })
  },
  submit(){
    wx.navigateTo({
      url: '/packageJ/anytime_service/my/role_apply_for/master_worker/master_worker?apply_type=3',
    })
  },
  onSearch(e) {
    this.setData({
      keyword:e.detail
    })
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.page>=this.data.total_page){
      return;
    }
    let page = this.data.page+ 1;
    this.getData(page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})